package com.lenovo.smarttraffic.wjy;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.ui.activity.BaseActivity;

import java.io.Serializable;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class wjy_lxzs3 extends BaseActivity {

    private ImageView l3image;
    private TextView sightscript;
    private RatingBar lxratingBar;
    private TextView teltext;

    int[] image = new int[]{R.mipmap.response,R.mipmap.response2,R.mipmap.response3,R.mipmap.response4,R.mipmap.response5,R.mipmap.response6,R.mipmap.response8,R.mipmap.response8,R.mipmap.response9};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initToolBar(findViewById(R.id.toolbar),true,"详细信息");
        initview();

        initdata();

    }

    private void initdata() {
        Retrofit retrofit = new Retrofit.Builder().baseUrl("http://192.168.1.110:8088/transportservice/action/").addConverterFactory(GsonConverterFactory.create()).build();
        Interface_Sight interface_sight = retrofit.create(Interface_Sight.class);
        Call<Bean_Sightdata> user1 = interface_sight.getCall(new Bean_User1("user1"));
        user1.enqueue(new Callback<Bean_Sightdata>() {
            @Override
            public void onResponse(Call<Bean_Sightdata> call, Response<Bean_Sightdata> response) {
                if (response.code()==200){
                    Intent intent = getIntent();
                    Serializable lxzs3id = intent.getSerializableExtra("lxzs3id");
                    int id= (int) lxzs3id;
                    List<Bean_Sightdata.ROWSDETAILBean> rows_detail = response.body().getROWS_DETAIL();
                    l3image.setImageResource(image[id]);
                    teltext.setText(rows_detail.get(id).getTel());
                    sightscript.setText(rows_detail.get(id).getInfo());
                    lxratingBar.setRating(rows_detail.get(id).getRating());
                    teltext.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent();
                            intent.setAction(Intent.ACTION_CALL);
                            intent.setData(Uri.parse(String.valueOf(teltext.getText())));
                            startActivity(intent);
                        }
                    });
                }
            }

            @Override
            public void onFailure(Call<Bean_Sightdata> call, Throwable t) {
                Toast.makeText(wjy_lxzs3.this,"error",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initview() {

        l3image = (ImageView) findViewById(R.id.l3image);
        sightscript = (TextView) findViewById(R.id.sightscript);
        lxratingBar = (RatingBar) findViewById(R.id.lxratingBar);
        teltext = (TextView) findViewById(R.id.teltext);
        lxratingBar.setClickable(false);
    }


    @Override
    protected int getLayout() {
        return R.layout.activity_wjy_lxzs3;
    }
}
